package com.tjc.project.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RedissonConfig
 * @Author tjc
 **/
@Configuration
@Data
@ConfigurationProperties(prefix = "spring.redis")
public class RedissonConfig {

    private String host;
    private int port;

    @Bean
    public RedissonClient redissonClient() {
        // 1. Create config object
        Config config = new Config();

        String redisAddress = String.format("redis://%s:%d", host, port);

        config.useSingleServer()
                .setAddress(redisAddress)
                .setDatabase(0);


        return Redisson.create(config);

    }
}
